Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<chrono>: Avoid unnecessary use of concepts #1787

Merged

Conversation

StephanTLavavej
Copy link
Member

@StephanTLavavej StephanTLavavej commented Mar 28, 2021

Related to #1749 - we should avoid using concepts when __cpp_lib_concepts isn't defined.

  • Cleanup: When performing SFINAE in default template arguments, use class = void_t<decltype(EXPRESSION)> for consistency (and shorter mangled names, although that doesn't really matter). This is still different than the most common form of enable_if_t<CONDITION, int> = 0 SFINAE which handles multiple overloads with the same signature, but that should be ok.
  • Cleanup: Update the comments about ICU/IANA. Thanks to @mattjohnsonpint for explaining what's happening here in <chrono>: Should divergence between ICU and IANA be reported? #1786.
  • hh_mm_ss can static_assert _Is_duration_v.
    • This is consistent with time_point:

      STL/stl/inc/chrono

      Lines 198 to 206 in 6aed1a6

      template <class _Clock, class _Duration = typename _Clock::duration>
      class time_point { // represents a point in time
      public:
      using clock = _Clock;
      using duration = _Duration;
      using rep = typename _Duration::rep;
      using period = typename _Duration::period;
      static_assert(_Is_duration_v<_Duration>, "duration must be an instance of std::duration");
  • Cleanup: The static_assert _Is_duration_v messages now say "mandates".
    • time_point was talking about std::duration which isn't a thing! 😹
  • Reimplement clock_time_conversion Constraints/Mandates.
    • Thanks to @MattStephanson for help decoding the WP here (see [time.clock.cast.sys] and [time.clock.cast.utc] reuse "Duration" confusingly cplusplus/draft#4564).
    • This implements the Standardese more precisely - e.g. WG21-N4885 [time.clock.cast.sys]/1 "Constraints: SourceClock::to_sys(t) is well-formed." isn't concerned about the return type, only /2 "Mandates: SourceClock::to_sys(t) returns a sys_time<Duration>" is.
    • The part of the Mandates that says "where Duration is a valid chrono::duration specialization" is enforced by time_point itself (which we're going to instantiate while attempting to return it).
    • We need _SourceClock2 and _DestClock2 as an extra layer of indirection because these template parameters belong to the struct instead of the function.
  • Rewrite clock_cast metaprogramming.
    • This uses @CaseyCarter's "choice" approach from ranges. Here's it's almost too high-powered (compared to just directly testing these things in clock_cast's function body), but not quite - we need to implement [time.clock.cast.fn]/1 "Constraints: At least one of the following clock time conversion expressions is well-formed" (which wasn't previously implemented as a constraint - instead it was a static_assert which would be a Mandates), so the "choice" tech lets us reuse that work.

stl/inc/chrono Outdated Show resolved Hide resolved
@StephanTLavavej StephanTLavavej merged commit dde4623 into microsoft:feature/chrono Mar 29, 2021
@StephanTLavavej StephanTLavavej deleted the chrono_concepts branch March 29, 2021 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chrono C++20 chrono cxx20 C++20 feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants